#include "Core/Log/LogManager.h"
#include "Core/Array/Array.h"
#include "Core/String/String.h"
#include "Core/Time/TimeMeasure.h"
#include "Core/Profile/CodeProfile.h"
#include "ArrayTest.h"

const char * ArrayTest::GetName() const
{
	return "Array Test";
}

error ArrayTest::Create()
{
	if(Failed(UnitTest::Create()))
		return errFailed;

	return errOK;
}

error ArrayTest::Destroy()
{
	if(Failed(UnitTest::Destroy()))
		return errFailed;

	return errOK;
}

error ArrayTest::Execute()
{
	PROFILE(GetName());

	Array< int > arrInt1(1024);

	if(arrInt1.Size() != 1024)
		return errFailed;

	if(arrInt1.Capacity() != 1024)
		return errFailed;

	arrInt1.Reset();

	if(arrInt1.Size() != 0)
		return errFailed;

	if(arrInt1.Capacity() != 1024)
		return errFailed;

	arrInt1.Clear();

	if(arrInt1.Size() != 0)
		return errFailed;

	if(arrInt1.Capacity() != 0)
		return errFailed;

	for(int i = 0; i < 2048; ++i)
		arrInt1.Push_Back(i);

	if(arrInt1.Size() != 2048)
		return errFailed;

	if(arrInt1.Capacity() != 2048)
		return errFailed;

	for(int i = 0; i < 2048; ++i)
	{
		if(arrInt1[i] != i)
			return errFailed;
	}

	if(arrInt1.Front() != 0)
		return errFailed;

	if(arrInt1.Back() != 2047)
		return errFailed;

	Array< int > arrInt2(arrInt1);

	if(arrInt1 != arrInt2)
		return errFailed;

	Array< String > arrStr;
	arrStr.Push_Back("toto");
	arrStr.Push_Front("tata");
	arrStr.Push_Back("titi");
	arrStr.Push_Back("tutu");

	int iIndex = 0;
	for(Array<String>::Iterator it = arrStr.Begin(); it != arrStr.End(); ++it, ++iIndex)
	{
		if( (*it) != arrStr[iIndex] )
			return errFailed;
	}

	Array< String >::ConstIterator itFind = arrStr.Find("tata");
	if( itFind != arrStr.Begin() )
		return errFailed;

	arrStr.Remove(itFind);
	if(arrStr.Size() != 3)
		return errFailed;

	return errOK;
}
